/*
 * Copyright (c) Huawei Technologies Co.,Ltd. 2023. All rights reserved.
 */
package org.opengauss.intercept;

import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.session.ResultHandler;

import java.sql.Connection;
import java.sql.Statement;

/**
 * Title: the StatementIntercept class.
 * <p>
 * Description:
 *
 * @author justbk
 * @version [Tools 0.0.1, 2023/7/24]
 * @since 2023/7/24
 */
@Intercepts(value = {
        @Signature(type= StatementHandler.class, method = "query", args = {Statement.class, ResultHandler.class}),
        @Signature(type= StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class}),
        @Signature(type= StatementHandler.class, method = "parameterize", args = {Statement.class})
})
public class StmtIntercept implements Interceptor {
    @Override
    public Object intercept(final Invocation invocation) throws Throwable {
        return DataRecordFactory.getStmtRecord().doRecord(invocation);
    }
    
    @Override
    public Object plugin(final Object target) {
        return Plugin.wrap(target, this);
    }
}
